import os
import sys
import time
from selenium.webdriver.common.by import By
from Base.base_action import BaseAction


class openDisplay(BaseAction):
    app_launch = (By.XPATH, "//*[contains(@text,'你今天真好看')]")  # app
    skip_loc = (By.ID, "org.c2h4.afei.beauty:id/cdpv_time")  # 跳过
    swipe_right = (500, 1000, 100, 1000, 500)

    def open_display(self):
        while True:
            try:
                self.click_element(self.app_launch)
                break
            except:
                self.swipe(*self.swipe_right)
        time.sleep(3)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        skip = None
        try:
            skip = self.find_element(openDisplay.skip_loc)
        except:
            pass
        assert skip is not None, "'跳过'不在页面中，开屏页面未正常显示"  # 断言， '跳过'在页面中
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    def skip_display(self):
        while True:
            try:
                self.click_element(self.app_launch)
                break
            except:
                self.swipe(*self.swipe_right)
        self.click_element(self.skip_loc)
        time.sleep(1)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        skip = None
        try:
            skip = self.find_element(openDisplay.skip_loc)
        except:
            pass
        assert skip is None, "'跳过'在页面中，开屏页面未跳过"  # 断言，'跳过'不在页面中
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    def jump_to_product(self):
        while True:
            try:
                self.click_element(self.app_launch)
                break
            except:
                self.swipe(*self.swipe_right)
        time.sleep(3)
        self.tab(x=500, y=1000)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(3)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")
